package acwing.动态规划;

/**
 * province
 *
 * @author yang
 * @date 2021/11/22
 */
final class province
{

    private final String name;//省份名称

    private final String[] city;//地级市

    private final String[][] xianqu;

    String[] newCity;
    int l1; // 新数组的长度
    String[][] newXianQu;
    int row; // 新数组的行
    int list; // 列
    public province(String name, String[] city, String[][] xianqu) {
        this.name = name;
        this.city = city;
        this.xianqu = xianqu;
        l1 = city.length;
        row = xianqu.length;
        list = xianqu[0].length;
        newCity = new String[l1];
        // copy
        for (int i = 0; i < l1; i++) {
            newCity[i] = city[i];
        }
        newXianQu = new String[row][list];
        for (int i = 0; i < row; i++) {
            for (int j = 0; j < list; j++) {
                newXianQu[i][j] = xianqu[i][j];

            }
        }
    }

    public final String getName()

    {

        return name;

    }

    public final String[] getCity()

    {

        return newCity.clone();

    }

    public final String[][] getXianqu() {
         // 如果我们创建一维数组的克隆，它会创建Java数组的深层副本(深拷贝)。
        // 这意味着，它将复制实际值。 但是，如果我们创建多维数组的克隆，
        // 它会创建Java数组的浅层副本(浅拷贝)，这意味着它会复制引用
        String[][] clone = new String[row][list];
        for (int i = 0; i < row; i++) clone[i] = newXianQu[i].clone(); // 一行一行的拷贝

        return clone;

    }

}

class Main {



    public static void main(String[] args) {

        String[] a = new String[]{"南昌", "九江", "上饶"};

        String[][] b = new String[][]{{"新建", "进贤"}, {"武宁", "修水"}, {"万年", "余干"}};

        province j1 = new province("江西", a, b);

        System.out.println(j1.getName());

        //以下3条语句验证city是否可以被串改

        a[0] = "dd";

        j1.getCity()[0] = "dd";

        System.out.println(j1.getCity()[0]);

        //以下3条语句验证xianqu是否可以被串改

        b[0][0] = "dd";


        j1.getXianqu()[0][0] = "dd";

        System.out.println(j1.getXianqu()[0][0]);
    }

}
